// JavaScript Document
function getPos(obj) {
	while (obj && (obj.type == 'hidden' || obj.nodeType != 1)) {
		obj = obj.nextSibling;
	}
	var curleft = curtop = 0;
	if (obj && obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			var origcurleft = curleft;
			curleft += obj.offsetLeft;
			if (curleft < 0) {
				curleft = origcurleft;
			}
			curtop += obj.offsetTop;
		}
	}
	return [curleft,curtop];
}
function toggleVMenu(id){
	//alert($("#vmenu_li_" + id).attr("style"));
	if ($("#vmenu_li_" + id).attr("style") == "display: none;"){
		$("#vmenu_li_" + id).attr("style", "display: block;");
	}else{
		$("#vmenu_li_" + id).attr("style", "display: none;");	
	}
}
function changeTab(i){
	$("#tab1").removeClass();
	$("#tab2").removeClass();
	$("#tab3").removeClass();
	if (i==1){
		$("#tab1").addClass("on");
		$("#tab1_content").attr("style", "display:block");
		$("#tab2_content").attr("style", "display:none");
		$("#tab3_content").attr("style", "display:none");
	}else if (i==2){
		$("#tab2").addClass("on");
		$("#tab1_content").attr("style", "display:none");
		$("#tab2_content").attr("style", "display:block");
		$("#tab3_content").attr("style", "display:none");
	}else{
		$("#tab3").addClass("on");
		$("#tab1_content").attr("style", "display:none");
		$("#tab2_content").attr("style", "display:none");		
		$("#tab3_content").attr("style", "display:block");		
	}
	return false;
}
function start_topnav(){
	$("ul#topnav li").hover(
		function() { //Hover over event on list item
			$(this).css({ 'background' : '#1376c9 url(../images/topnav_active.gif) repeat-x'}); //Add background color + image on hovered list item
			$(this).find("span").show(); //Show the subnav
		} , 
		function() { //on hover out...
			$(this).css({ 'background' : 'none'}); //Ditch the background
			$(this).find("span").hide(); //Hide the subnav
			$("#topnav_li_1").addClass("current");
			$("#topnav_span_1").show();
		}
	);
}
function setMenuClicked(i){
	var options = { path: '/', expires: 1 };
	$.cookie('menu_a_clicked', i, options);
}
function getMenuClicked(){
	return $.cookie('menu_a_clicked');
}
function deletetMenuClicked(){
	var options = { path: '/', expires: 1 };
	$.cookie('menu_a_clicked', null, options);
}
function setMenuActive(){
	var i;
	i = getMenuClicked();
	if (i==0 || i==null) i = 1;
	$("#menu_a_" + i).addClass("active");
}
/*Custom function*/
function showRequest(formData, jqForm, options) {
	var fileToUploadValue = $('#upload_file').fieldValue();
	if (!fileToUploadValue[0]) {
		alert('Please select a file.');
		return false;
	}
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(fileToUploadValue)) {
		alert('Choose file .JPG, .JPEG, .GIF');
		$("#loading").hide();
		return false;
	}
	$("#loading").show();
	return true;
} 

function showResponse(data)  {
	if(!/(\.bmp|\.gif|\.jpg|\.jpeg)$/i.test(data)) {
		alert('Upload error \r\nChoose another file');
		$("#loading").hide();
		return false;
	}
	if ($("#image").length > 0){
		$("#image").val(data);
	}else
	if ($("#logo").length > 0){
		$("#logo").val(data);
	}
	$("#image_avatar").attr("src", nvcms_url+"/uploads/" +data);
	$("#loading").hide();
} 
function ajaxUpload(){
	var options = {
		beforeSubmit:  	showRequest,
		success:       	showResponse,
		url:       		nvcms_url + "/?mod=account&act=uploader",  // your upload script
		dataType:		'html'
	};
	$("#theForm").ajaxSubmit(options);
}
function cancelDialog(){
	$("#dialog").hide();
	$("#result").html("");
	$("#loading").hide();
	if (do_action==1){
		location.reload(true);
		do_action = 0;
	}
	return false;
}
function checkSalaryRange(){
	var i;
	i = $("#salaryrange").val();
	if (i==0){
		$("#span_salaryrange").show();
	}else{
		$("#span_salaryrange").hide();		
	}
}
function checkWorkingPlace(t){
	var i1, i2, i3;
	i1 = $("#workingplace1").val();
	i2 = $("#workingplace2").val();
	i3 = $("#workingplace3").val();
	if (t==2){
		if (i2==i1 || i2==i3){
			alert(Choose_other);
			$("#workingplace2").val(0);
		}
	}else{
		if (i3==i1 || i2==i3){
			alert(Choose_other);
			$("#workingplace3").val(0);
		}		
	}
}
function checkOccup(t){
	var i;
	var i1, i2, i3;
	i1 = $("#occup1").val();
	i2 = $("#occup2").val();
	i3 = $("#occup3").val();
	if (t==2){
		if (i2==i1 || i2==i3){
			alert(Choose_other);
			$("#occup2").val(0);
		}
	}else{
		if (i3==i1 || i2==i3){
			alert(Choose_other);
			$("#occup3").val(0);
		}		
	}
}
function check3Select(s1, s2, s3, t){
	var i;
	var i1, i2, i3;
	i1 = $("#"+s1).val();
	i2 = $("#"+s2).val();
	i3 = $("#"+s3).val();
	if (t==1){
		if (i1==i2){
			$("#"+s2).val(0);
		}
		if (i1==i3){
			$("#"+s3).val(0);
		}
		var idx = parseInt($("#"+s1)[0].selectedIndex);
		var len = $("#"+s1+" option").length;
		if (idx+1 == len){
			$("#nganhnghe12").hide();
			$("#nganhnghe13").hide();
			$("#nganhnghe1_khac").show();
			$("#nganhnghe1_khac").focus();
		}else{
			$("#nganhnghe12").show();
			$("#nganhnghe13").show();
			$("#nganhnghe1_khac").hide();
		}
	}else
	if (t==2 && i2!=0){
		if (i2==i1 || i2==i3){
			alert(Choose_other);
			$("#"+s2).val(0);
		}
		if (i1==0){
			$("#"+s2).val(0);
		}
	}else if (t==3 && i3!=0){
		if (i3==i1 || i2==i3){
			alert(Choose_other);
			$("#"+s3).val(0);
		}
		if (i1==0 || i2==0){
			$("#"+s3).val(0);
		}
	}	
}
function checkWorkingTime(s1){
	var i1, len;
	i1 = parseInt($("#"+s1)[0].selectedIndex);
	len = $("#"+s1+" option").length;
	if ( i1+1 == len){
		$("#"+s1+"_khac").show();
		$("#"+s1+"_khac").focus();
	}else{
		$("#"+s1+"_khac").hide();
	}
	return true;
}

function checkAll(fid){
	var frm = document.getElementById(fid);
	for (var i=0;i<frm.elements.length;i++)
	{
		var e = frm.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			e.checked = frm.allbox.checked;
		}
	}
}
function checkAll2(fid){
	var frm = document.getElementById(fid);
	for (var i=0;i<frm.elements.length;i++)
	{
		var e = frm.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			e.checked = 1;
		}
	}
}
function unCheckAll(fid){
	var frm = document.getElementById(fid);
	for (var i=0;i<frm.elements.length;i++)
	{
		var e = frm.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			e.checked = 0;
		}
	}
}
function getDistrict0(){
	var province_id, req, html;
	province_id = $("#province_id").val();
	req = nvcms_url + "/?act=getOptionsDistrict&type=0&province_id="+province_id;
	$("#district_id").load(req);
}
function getDistrict2(){
	var province_id, req, html;
	province_id = $("#province_id").val();
	req = nvcms_url + "/?act=getOptionsDistrict&type=2&province_id="+province_id;
	$("#district_id").load(req);
}


function ITMCheckAll() {
	 var fmobj = document.theForm;
	 for (var i=0;i<fmobj.elements.length;i++) {
		 var e = fmobj.elements[i];
		 if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
			 e.checked = fmobj.allbox.checked;
		 }
	 }
	 return true;
}
function ITMconfirmEdit() {
	var total = 0;
	var fmobj = document.theForm;
	var pvalue = 0;
	for (var i=0;i<fmobj.elements.length;i++) {
	 var e = fmobj.elements[i];
	 if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
		 if (e.checked){ 
		 	total++;
			pvalue = e.value;
		 }
	 }
	}
	if (total==0 ){ 
		alert(You_must_choose_one+'!');
		return false;
	}
	return true;
}
function ITMconfirmDelete(){
	return confirm(Are_you_sure+'?');
}
var arr_pr_id = new Array();
function showStats(oX,oY, pr_id){
	var o = document.getElementById("main_map");
	var arr = getPos(o);
	curX = oX + arr[0];
	curY = oY + arr[1] +20;
	$("#map_tooltip").css({left:curX+'px', top:curY+"px"});
	$("#map_tooltip").show();
	if (arr_pr_id[pr_id]==null){
		$("#map_tooltip_loading").show();
		$("#map_tooltip .tooltip").load(nvcms_url+"/?act=getHomeStats&pr_id="+pr_id, function(response, status, xhr) {
			arr_pr_id[pr_id] = response;
			$("#map_tooltip_loading").hide();
			$("#map_tooltip .tooltip").show();
		});
	}else{
		$("#map_tooltip .tooltip").html(arr_pr_id[pr_id]);
		$("#map_tooltip_loading").hide();
		$("#map_tooltip .tooltip").show();
	}
}
function hideShowStats(oX,oY){
	$("#map_tooltip").hide();
	$("#map_tooltip .tooltip").hide();
}

function print_resume_detail(resume_id)
{
	var width = screen.width-20;
	var height = 600;
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
	var url= nvcms_url+'/?act=detailresume&mode=print&resume_id='+resume_id;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=no';
	newwin=window.open(url,'Print', params);
	if (window.focus) {newwin.focus()}
	return false;
}
function print_resume_detail2(resume_id)
{
	var width = screen.width-20;
	var height = 600;
	var left = (screen.width - width)/2;
	var top = (screen.height - height)/2;
	var url= nvcms_url+'/?act=printresume&mode=print&resume_id='+resume_id;
	var params = 'width='+width+', height='+height;
	params += ', top='+top+', left='+left;
	params += ', directories=no';
	params += ', location=no';
	params += ', menubar=no';
	params += ', resizable=no';
	params += ', scrollbars=yes';
	params += ', status=no';
	params += ', toolbar=no';
	newwin=window.open(url,'Print', params);
	if (window.focus) {newwin.focus()}
	return false;
}
function hideKhuCn(k){
	$("#khucn"+k).hide();
	$("#ul_khucn"+k).hide();
}

function autosave_resume(){
	var req = nvcms_url + "/index.php?mod=account&act=autosave";
	var q = $("#theForm").serialize();
	q = q + "&but=btnAutoSave";
	$.post(	req, 
		q,
		function(data){
			$("#span_draft_datetime").html(data);
			setTimeout("autosave_resume()", 120000);
		}
	);	
}
function load_resume_draft(){
	$("#loadDraft").val("LoadDraft");
	$("#theForm").submit();
}